<template>
  <div class="page-box">
    <!-- ! 筛选区 -->
    <div class="search-box">
      <el-form size="small" :inline="true" class="demo-form-inline">
        <el-form-item label="账号">
          <el-input v-model.trim="query.login_name" placeholder="请输入" style="width:230px" />
        </el-form-item>
        <el-form-item label="手机号">
          <el-input v-model.trim="query.phone" placeholder="请输入" style="width:230px" />
        </el-form-item>
        <el-form-item label="账号状态">
          <el-select v-model="query.status">
            <el-option label="全部" :value="2" />
            <el-option label="启用" :value="1" />
            <el-option label="冻结" :value="0" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" type="primary" @click="search">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="reset">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
    <!-- ! 工具条区域 -->
    <div class="tabbar-box">
      <el-row type="flex" justify="space-between">
        <div>
          <el-button plain type="primary" icon="el-icon-plus" size="mini">新增</el-button>
          <el-button plain type="warning" icon="el-icon-download" size="mini">导出</el-button>
        </div>
        <div>
          <el-button icon="el-icon-arrow-down" size="mini" circle />
          <el-button icon="el-icon-refresh" size="mini" circle />
          <el-button icon="el-icon-menu" size="mini" circle />
        </div>
      </el-row>
    </div>
    <!-- ! 表格区域 -->
    <div class="table-box">
      <el-table
        :data="list"
        style="width: 100%"
        border
      >
        <el-table-column type="index" label="#" width="50" />
        <el-table-column prop="login_name" label="账号" />
        <el-table-column prop="name" label="姓名" />
        <el-table-column prop="email" label="邮箱" />
        <el-table-column prop="phone" label="手机号" />
        <el-table-column label="角色">
          <template #default="{row}">
            <el-tag v-for="(item,index) in row.rolename" :key="index" type="success">{{ item }}</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="create_date" label="创建时间" />
        <el-table-column label="状态">
          <template #default="{row}">
            <el-switch
              v-model="row.status"
              :active-value="1"
              :inactive-value="0"
              active-text="启用"
              inactive-text="冻结"
            />
          </template>
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template #default>
            <el-row type="flex" justify="center">
              <el-button circle type="primary" icon="el-icon-edit" size="mini" />
              <el-button circle type="danger" icon="el-icon-delete" size="mini" />
            </el-row>
          </template>
        </el-table-column>

      </el-table>
    </div>
    <!-- ! 分页区域 -->
    <div class="page">
      <el-row type="flex" justify="end">
        <el-pagination
          background
          :current-page="query.page"
          :page-sizes="[5, 10, 15, 20]"
          :page-size="query.limit"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </el-row>
    </div>
    <!-- ! 弹层 -->
    <el-dialog />
  </div>
</template>
<script>
import { getUserList } from '@/api/system/user'
export default {
  data() {
    return {
      list: [],
      options: [],
      total: 0,
      query: {
        login_name: '',
        status: '全部',
        phone: '',
        page: 1,
        limit: 10
      }
    }
  },
  created() {
    this.initData()
  },
  methods: {
    // ! 筛选
    search() {
      this.query.page = 1
      this.initData()
    },
    // ! 重置
    reset() {
      this.query = {
        start_time: '',
        end_time: '',
        title: '',
        cateid: '',
        page: 1,
        limit: 10
      }
      this.time = ''
      this.initData()
    },
    // ! 分页
    handleSizeChange(value) {
      this.query.limit = value
      this.query.page = 1
      this.initData()
    },
    handleCurrentChange(value) {
      this.query.page = value
      this.initData()
    },
    // ! 获取初始化数据
    async initData() {
      const res = await getUserList(this.query)
      this.list = res.data
      this.total = res.count
    }
  }
}
</script>
<style lang="scss" scoped>
  .page-box {
    margin: 20px;
    padding: 20px;
    background-color: #fff;
    .search-box,.tabbar-box {
      padding-top: 10px;
      height: 50px;
    }

  }
  ::v-deep .el-dialog__header{
   padding: 15px 20px 10px!important;
    border-bottom: 1px solid #e9ecef;
    background-color: #fafafa;
  }

</style>
